<?xml version="1.0" encoding="UTF-8"?>
<!--
   - list2antxspec.xsl
   - Build utility for testing
   -
   - Copyright (c) 2011 Erik Hennum. All Rights Reserved.
   -
   - Licensed under the Apache License, Version 2.0 (the "License");
   - you may not use this file except in compliance with the License.
   - You may obtain a copy of the License at
   -
   - http://www.apache.org/licenses/LICENSE-2.0
   -
   - Unless required by applicable law or agreed to in writing, software
   - distributed under the License is distributed on an "AS IS" BASIS,
   - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   - See the License for the specific language governing permissions and
   - limitations under the License.
   -
   - The use of the Apache License does not indicate that this work is
   - associated with the Apache Software Foundation.
   -
  -->
<xsl:stylesheet version="2.0"
    xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
    xmlns:fn  = "http://www.w3.org/2005/xpath-functions"
    xmlns:xs  = "http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xsl fn xs">

<xsl:param name="basedir" as="xs:string"/>

<xsl:template match="/">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="filelist">
  <xsl:text>
</xsl:text>
  <project name="xspec-test" default="xspec-all" basedir="{$basedir}">
    <target name="xspec-all">
      <xsl:apply-templates/>
    </target>
  </project>
</xsl:template>

<xsl:template match="file">
  <xsl:variable name="root" select="fn:replace(@href,'\.xspec$','')"/>

  <xslt processor="trax">
    <xsl:attribute name="in">
      <xsl:text>${basedir}${file.separator}..${file.separator}</xsl:text>
      <xsl:value-of select="$root"/>
      <xsl:text>.xspec</xsl:text>
    </xsl:attribute>
    <xsl:attribute name="style">
      <xsl:text>${basedir}${file.separator}</xsl:text>
      <xsl:value-of select="$root"/>
      <xsl:text>.xsl</xsl:text>
    </xsl:attribute>
    <xsl:attribute name="out">
      <xsl:text>${basedir}${file.separator}</xsl:text>
      <xsl:value-of select="$root"/>
      <xsl:text>-result.xml</xsl:text>
    </xsl:attribute>
    <factory name="net.sf.saxon.TransformerFactoryImpl">
      <attribute name="http://saxon.sf.net/feature/initialTemplate">
        <xsl:attribute name="value">
          <xsl:text>{http://www.jenitennison.com/xslt/xspec}main</xsl:text>
        </xsl:attribute>
       </attribute>
    </factory> 
  </xslt>
</xsl:template>

<xsl:template match="node()">
  <xsl:copy-of select="."/>
</xsl:template>

</xsl:stylesheet>